package com.isoftstone.disk.controller;

import com.isoftstone.disk.service.DiskService;
import com.isoftstone.platform.controller.BaseController;
import com.isoftstone.platform.entity.PadingRstType;
import com.isoftstone.platform.model.entity.FileEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.logging.Logger;


@Controller
@RequestMapping("/recycle")
public class RecycleController  extends BaseController {
    private Logger logger = Logger.getLogger("RecycleController");

    @Resource
    private DiskService diskService;

    @RequestMapping("/file")
    public String ShowRecycleFiles(){
        return  "file/recycleFile";
    }

    @RequestMapping("/getDeleteFileslist")
    @ResponseBody
    public PadingRstType<FileEntity> getDeleteFileslist()  {
        PadingRstType<FileEntity> padingRstType = new PadingRstType<FileEntity>();
        padingRstType=diskService.getDeleteFileslist();
        return padingRstType;
    }

    //文件从回收站还原
    @RequestMapping(value = "/restore/{fileId:.+}")
    @ResponseBody
    public String recycle(@PathVariable("fileId") String fileId) {
        diskService.restore(Integer.valueOf(fileId));
        return buildSuccessJsonMsg("file.upload.success",null);
    }

    //文件删除 彻底删除
    @RequestMapping(value = "/delete/{fileId:.+}")
    @ResponseBody
    public String delete(@PathVariable("fileId") String fileId) {
        diskService.delete(fileId);
        return buildSuccessJsonMsg("file.upload.success",null);
    }

    //文件测试
    @RequestMapping(value = "/test/{fileId:.+}")
    @ResponseBody
    public String test(@PathVariable("fileId") String fileId) {
        diskService.delete(fileId);
        return buildSuccessJsonMsg("file.upload.success",null);
    }


}

